<template>
  <transition name="">
    <div :class="['message-mask', {'message-mask_transprent': !modal}]" v-if="visible">
      <div class="message-content">
        <div class="message-title">{{type === 'warning' ? '警告' : '提示'}}</div>
        <div class="message-text">{{content}}</div>
        <div class="message-btn_group">
          <span class="message-btn_left" @click='leftFn'>{{leftBtn}}</span>
          <span class="message-btn_right" @click="rightFn">{{rightBtn}}</span>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
export default {
  name: 'message',
  data() {
    return {
      title: '提示',
      text: 'hello,world!',
      leftBtn: '取消',
      rightBtn: '确定',
    };
  },
  methods: {
    leftFn() {
      this.left();
      this.$emit('update:visible', false);
    },
    rightFn() {
      this.right();
      this.$emit('update:visible', false);
    },
  },
  props: ['visible', 'left', 'right', 'type', 'content', 'modal'],
};
</script>

<style scoped>
  .message-mask{
    position: fixed;
    z-index: 999;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0,0,0,.2);
  }
  .message-mask_transprent{
    background: rgba(0,0,0,0);
  }
  .message-content{
    width: 80%;
    max-width: 300px;
    background: #fff;
    color: #444;
    border-radius: 3px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
  }
  .message-title{
    text-align: center;
    line-height: 46px;
  }
  .message-text{
    text-align: center;
    padding: 12px;
    box-sizing: border-box;
  }
  .message-btn_group{
    font-size: 0;
    border-top: 1px solid #ccc;
  }
  .message-btn_group>span{
    display: inline-block;
    width: 50%;
    text-align: center;
    line-height: 40px;
    font-size: 15px;
  }
</style>
